package cn.wolfcode.p2p.controller;

import cn.wolfcode.p2p.base.exception.CustomerException;
import cn.wolfcode.p2p.base.query.QueryObject;
import cn.wolfcode.p2p.business.domain.PlatformBankInfo;
import cn.wolfcode.p2p.business.query.PlatformBankInfoQuery;
import cn.wolfcode.p2p.business.service.IPlatformBankInfoService;
import cn.wolfcode.p2p.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CompanyBankController {

    @Autowired
    private IPlatformBankInfoService platformBankInfoService;

    @RequestMapping("companyBank_list")
    public String companyBankList(Model model, @ModelAttribute("qo") PlatformBankInfoQuery qo){
        model.addAttribute("pageInfo", platformBankInfoService.query(qo));
        return "platformbankinfo/list";
    }

    @RequestMapping("companyBank_update")
    @ResponseBody
    public JsonResult companyBankUpdate(PlatformBankInfo platformBankInfo){
       JsonResult jsonResult = new JsonResult();
       try {
          platformBankInfoService.saveOrUpdate(platformBankInfo);
       } catch (CustomerException e) {
           jsonResult.setMessage(e.getMessage());
           throw new CustomerException(e.getMessage());
       } catch (Exception e) {
           e.printStackTrace();
           throw new RuntimeException("系统繁忙中,请稍后再试");
       }
       return jsonResult;
    }
}
